package FileIO;

import java.io.File;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import model.Escenario;

import org.w3c.dom.Document;

public abstract class Persistible {

	protected void escribirDocumentoEnArchivo(Document doc,String nombreArchivo){
		// write the content into xml file
		try {
			TransformerFactory transformerFactory = TransformerFactory.newInstance();
			Transformer transformer = transformerFactory.newTransformer();
			DOMSource source = new DOMSource(doc);
			StreamResult result = new StreamResult(new File(nombreArchivo));
			transformer.transform(source, result);
		} catch (TransformerException e) {
			e.printStackTrace();
		}
	}
	
	protected String getNumberWithCero(int numero) {
	    if (numero >=0 && numero <=9){
	    	return "0" + String.valueOf(numero);
	    }
	    return String.valueOf(numero);
	}	
	
	public abstract void persistir(Escenario escenario);
	
}
